<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>三级项目统计</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/excellentexport/excellentexport.min.js"></script>
	<script src="${ctxStatic}/echart/echarts.min.js"></script>
	<style type="text/css">
		.tb1th{
			padding-left:80px !important;
			padding-right: 80px !important;
		}
		#tableDiv{
			max-width: 100%;
			overflow-x: scroll;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出预算明细数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/oa/budget/export");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/oa/budget/listBudgetEdit">三级统计</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="budget" action="${ctx}/oa/budget/listBudgetStatistics" method="post" class="breadcrumb form-search">
		<label>预算年度：&nbsp;</label>
		<input id="annual" name="annual" type="text" readonly="readonly" maxlength="20" class="required input-medium Wdate"
			   value="${budget.annual}" onclick="WdatePicker({dateFmt:'yyyy',isShowClear:false});"/>
		<label>处室：&nbsp;</label>
		<sys:treeselect id="office" name="office.id" value="${office.id}" labelName="office.name" labelValue="${budget.office.name}"
						title="处室" url="/sys/office/treeData" cssClass="required recipient" cssStyle="width:150px"
						allowClear="true" notAllowSelectParent="true" smallBtn="false"/>

		<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>

		<%--<input download="预算统计.xls" id="btnExport" class="btn btn-primary"  type="button" onclick="return ExcellentExport.excel(this, 'contentTable', '三级统计');" value="导出"/>--%>
		<a class="btn btn-primary" download="预算统计.xls" href="#" onclick="return ExcellentExport.excel(this, 'contentTable', '三级统计');">导出</a>
		<input id="btnExport" class="btn btn-primary" type="button" value="导出明细"/>

	</form:form>
	<sys:message content="${message}"/>
	<%--<div id="div_echart" style="width: 100%;height:300px;"></div>--%>
    <div id="div_echart_2" style="width: 100%;height:300px;"></div>

    <div id="tableDiv">
		<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<thead><tr>
				<th class="tb1th">经济科目</th>
				<c:forEach items="${categories}" var="category">
					<th class="category" category_name="${category.name}">&nbsp;&nbsp;${category.name}（万元）&nbsp;&nbsp;</th>
				</c:forEach>
				<th>合计（万元）</th>
			<tbody>
				<tr><td>合计</td>
					<c:forEach items="${categories}" var="category">
						<td class="category_total">
							<fmt:formatNumber type="number" maxFractionDigits="4" value="${category.total}"></fmt:formatNumber>

						</td>
					</c:forEach>
					<td>
						<fmt:formatNumber type="number" maxFractionDigits="4" value="${sum}"></fmt:formatNumber>
					</td>
				</tr>
				<c:forEach items="${subjects}" var="subject" varStatus="status">
					<tr>
						<td class="subjectName" value="${subject.code}">[${subject.code}]${subject.name}</td>
						<c:forEach items="${categories}" var="category">
							<td>
								<fmt:formatNumber type="number" maxFractionDigits="4" value="${category.subjects[status.index].money}"></fmt:formatNumber>
							</td>
						</c:forEach>
						<td class="subjectSum">
							<fmt:formatNumber type="number" maxFractionDigits="4" value="${subjects[status.index].sum}"></fmt:formatNumber>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
	<script>
		/*// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.getElementById('div_echart'));
		var subjects = ['经济科目'];
		var subjectNameArray = [];
		var subjectSumArray = [];
		// 指定图表的配置项和数据
		option = {
			title : {
			},
			tooltip : {
				trigger: 'axis'
			},
			legend: {
				data:subjects
			},
			toolbox: {
				show : true,
				feature : {
					dataView : {show: true, readOnly: false},
					magicType : {show: true, type: ['line', 'bar']},
					restore : {show: true},
					saveAsImage : {show: true}
				}
			},
			calculable : true,
			xAxis : [
				{
					type : 'category',
					data : subjectNameArray
				}
			],
			yAxis : [
				{
					type : 'value'
				}
			],
			series : [
				{
					name:'经济科目',
					type:'bar',
					data:subjectSumArray
				}
			]
		};
		$(".subjectName").each(function () {
			subjectNameArray.push($(this).html());
		});
		$(".subjectSum").each(function () {
			subjectSumArray.push($(this).html());
		})
		myChart.setOption(option);*/

		// 使用刚指定的配置项和数据显示图表。


        // 基于准备好的dom，初始化echarts实例
        var myChart2 = echarts.init(document.getElementById('div_echart_2'));
        var subjects2 = ['类别'];
        var subjectNameArray2 = [];
        var subjectSumArray2 = [];
        // 指定图表的配置项和数据
        option2 = {
            title : {
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:subjects2
            },
            toolbox: {
                show : true,
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : subjectNameArray2
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    name:'类别',
                    type:'bar',
                    data:subjectSumArray2
                }
            ]
        };
        $(".category").each(function () {
            subjectNameArray2.push($(this).attr('category_name'));
        });
        $(".category_total").each(function () {
            subjectSumArray2.push($(this).html());
        })
        myChart2.setOption(option2);
	</script>
</body>
</html>
